home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / polardrw / data.z / ScrollDemoDlg.cpp < prev    next >
C/C++ Source or Header  |  1999-05-24  |  7KB  |  255 lines

  1. // ScrollDemoDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "ScrollDemo.h"
  6. #include "ScrollDemoDlg.h"
  7. #include "pdrawconst.h"
  8. #include "math.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CAboutDlg dialog used for App About
  18.  
  19. class CAboutDlg : public CDialog
  20. {
  21. public:
  22.     CAboutDlg();
  23.  
  24. // Dialog Data
  25.     //{{AFX_DATA(CAboutDlg)
  26.     enum { IDD = IDD_ABOUTBOX };
  27.     //}}AFX_DATA
  28.  
  29.     // ClassWizard generated virtual function overrides
  30.     //{{AFX_VIRTUAL(CAboutDlg)
  31.     protected:
  32.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  33.     //}}AFX_VIRTUAL
  34.  
  35. // Implementation
  36. protected:
  37.     //{{AFX_MSG(CAboutDlg)
  38.     //}}AFX_MSG
  39.     DECLARE_MESSAGE_MAP()
  40. };
  41.  
  42. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  43. {
  44.     //{{AFX_DATA_INIT(CAboutDlg)
  45.     //}}AFX_DATA_INIT
  46. }
  47.  
  48. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50.     CDialog::DoDataExchange(pDX);
  51.     //{{AFX_DATA_MAP(CAboutDlg)
  52.     //}}AFX_DATA_MAP
  53. }
  54.  
  55. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  56.     //{{AFX_MSG_MAP(CAboutDlg)
  57.         // No message handlers
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CScrollDemoDlg dialog
  63.  
  64. CScrollDemoDlg::CScrollDemoDlg(CWnd* pParent /*=NULL*/)
  65.     : CDialog(CScrollDemoDlg::IDD, pParent)
  66. {
  67.     //{{AFX_DATA_INIT(CScrollDemoDlg)
  68.         // NOTE: the ClassWizard will add member initialization here
  69.     //}}AFX_DATA_INIT
  70.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  71.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  72.     m_nTimer = -1;
  73.     m_lLeftArrow = -1;
  74.     m_lSquare = -1;
  75.     m_lText = -1;
  76.  
  77. }
  78.  
  79. void CScrollDemoDlg::DoDataExchange(CDataExchange* pDX)
  80. {
  81.     CDialog::DoDataExchange(pDX);
  82.     //{{AFX_DATA_MAP(CScrollDemoDlg)
  83.     DDX_Control(pDX, IDC_POLARDRAWCTRL1, m_PolarDraw);
  84.     //}}AFX_DATA_MAP
  85. }
  86.  
  87. BEGIN_MESSAGE_MAP(CScrollDemoDlg, CDialog)
  88.     //{{AFX_MSG_MAP(CScrollDemoDlg)
  89.     ON_WM_SYSCOMMAND()
  90.     ON_WM_PAINT()
  91.     ON_WM_QUERYDRAGICON()
  92.     ON_WM_TIMER()
  93.     ON_WM_DESTROY()
  94.     //}}AFX_MSG_MAP
  95. END_MESSAGE_MAP()
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // CScrollDemoDlg message handlers
  99.  
  100. BOOL CScrollDemoDlg::OnInitDialog()
  101. {
  102.     CDialog::OnInitDialog();
  103.  
  104.     // Add "About..." menu item to system menu.
  105.  
  106.     // IDM_ABOUTBOX must be in the system command range.
  107.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  108.     ASSERT(IDM_ABOUTBOX < 0xF000);
  109.  
  110.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  111.     if (pSysMenu != NULL)
  112.     {
  113.         CString strAboutMenu;
  114.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  115.         if (!strAboutMenu.IsEmpty())
  116.         {
  117.             pSysMenu->AppendMenu(MF_SEPARATOR);
  118.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  119.         }
  120.     }
  121.  
  122.     // Set the icon for this dialog.  The framework does this automatically
  123.     //  when the application's main window is not a dialog
  124.     SetIcon(m_hIcon, TRUE);            // Set big icon
  125.     SetIcon(m_hIcon, FALSE);        // Set small icon
  126.     
  127.     // Here, we create shapes and set their attributes:
  128.     m_lSquare = m_PolarDraw.AddShape(polRectangle, 50, 50, 100, 100);
  129.     m_lLeftArrow = m_PolarDraw.AddShape(polLeftArrow, 105, 105, 205, 155);
  130.     if(m_lSquare > -1)
  131.     {
  132.         m_PolarDraw.SetShapeFillTexture(m_lSquare, polGreenMarble);
  133.     }
  134.     if(m_lLeftArrow > -1)
  135.     {
  136.         m_PolarDraw.SetShapeFillPattern(m_lLeftArrow, polSphere, RGB(255,0,0), RGB(255,255,0));
  137.     }
  138.  
  139.     m_lText =  m_PolarDraw.AddShape(polPlainText, 50, 50, 205, 155);
  140.     if (m_lText > 0)
  141.     {
  142.         m_PolarDraw.SetShapeText(m_lText, "Test");
  143.         m_PolarDraw.SetShapePos(m_lText, 50, 50, 205, 155);
  144.         m_PolarDraw.SetShapeLensType(m_lText, polInvert);
  145.         m_PolarDraw.SetShapeHasLens(m_lText, TRUE);
  146.         m_PolarDraw.SetShapeHasLine(m_lText, FALSE);
  147.     }
  148.  
  149.     m_lDiamond = m_PolarDraw.AddShape(polDiamond, 50, 150, 205, 225);
  150.     if (m_lDiamond > 0)
  151.     {
  152.         m_PolarDraw.SetShapeFillType(m_lDiamond, polShade);
  153.         m_PolarDraw.SetShapeFillColor(m_lDiamond, RGB(255,0,0));
  154.         m_PolarDraw.SetShapeFillBackColor(m_lDiamond, RGB(255,255,0));
  155.         m_PolarDraw.SetShapeFillAngle(m_lDiamond, 90);
  156.     }
  157.  
  158.     // Now set theoptimal zoom:
  159.     m_PolarDraw.FitToPage();
  160.     m_PolarDraw.SetEnableRendering(TRUE);
  161.     m_nTimer = SetTimer(1, 50, NULL);
  162.  
  163.     
  164.     return TRUE;  // return TRUE  unless you set the focus to a control
  165. }
  166.  
  167. void CScrollDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  168. {
  169.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  170.     {
  171.         CAboutDlg dlgAbout;
  172.         dlgAbout.DoModal();
  173.     }
  174.     else
  175.     {
  176.         CDialog::OnSysCommand(nID, lParam);
  177.     }
  178. }
  179.  
  180. // If you add a minimize button to your dialog, you will need the code below
  181. //  to draw the icon.  For MFC applications using the document/view model,
  182. //  this is automatically done for you by the framework.
  183.  
  184. void CScrollDemoDlg::OnPaint() 
  185. {
  186.     if (IsIconic())
  187.     {
  188.         CPaintDC dc(this); // device context for painting
  189.  
  190.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  191.  
  192.         // Center icon in client rectangle
  193.         int cxIcon = GetSystemMetrics(SM_CXICON);
  194.         int cyIcon = GetSystemMetrics(SM_CYICON);
  195.         CRect rect;
  196.         GetClientRect(&rect);
  197.         int x = (rect.Width() - cxIcon + 1) / 2;
  198.         int y = (rect.Height() - cyIcon + 1) / 2;
  199.  
  200.         // Draw the icon
  201.         dc.DrawIcon(x, y, m_hIcon);
  202.     }
  203.     else
  204.     {
  205.         CDialog::OnPaint();
  206.     }
  207. }
  208.  
  209. // The system calls this to obtain the cursor to display while the user drags
  210. //  the minimized window.
  211. HCURSOR CScrollDemoDlg::OnQueryDragIcon()
  212. {
  213.     return (HCURSOR) m_hIcon;
  214. }
  215.  
  216. void CScrollDemoDlg::OnTimer(UINT nIDEvent) 
  217. {
  218.     // TODO: Add your message handler code here and/or call default
  219.     if(nIDEvent == m_nTimer)
  220.     {
  221.         // disable rendering so the canvas is not redrawn after each line:
  222.         m_PolarDraw.SetEnableRendering(FALSE);
  223.  
  224.         // Set shape attributes:
  225.         m_PolarDraw.RotateShape(m_lSquare, 5);
  226.         m_PolarDraw.RotateShape(m_lLeftArrow, -5);
  227.         m_PolarDraw.RotateShape(m_lText, 2);
  228.         long lRot1 = m_PolarDraw.GetShapeRotation(m_lLeftArrow);
  229.         long lRot2 = m_PolarDraw.GetShapeRotation(m_lText);
  230.         long lMove1 = (long)(30 * sin((float)lRot2/16));
  231.         m_PolarDraw.SetShapeLeft(m_lDiamond, 50 - lMove1);
  232.         m_PolarDraw.SetShapeRight(m_lDiamond, 205 + lMove1);
  233.         m_PolarDraw.SetShapeTop(m_lDiamond, 150 + lMove1/2);
  234.         m_PolarDraw.SetShapeBottom(m_lDiamond, 225 - lMove1/2);
  235.         // enable rendering now:
  236.         m_PolarDraw.SetEnableRendering(TRUE);
  237.         long lMove2 = (long)(40 * sin((float)lRot2/20));
  238.         long lMove3 = (long)(40 * cos((float)lRot2/20));
  239.         // following line will reposition the page inside the canvas
  240.         // and also re-render the canvas:
  241.         m_PolarDraw.SetPageOrigin(351 - lMove3, 395 - lMove2);
  242.     }
  243.     
  244.     CDialog::OnTimer(nIDEvent);
  245. }
  246.  
  247. void CScrollDemoDlg::OnDestroy() 
  248. {
  249.     CDialog::OnDestroy();
  250.     
  251.     // Kill the timer that we created in OnInitialUpdate()
  252.     if(m_nTimer != -1)
  253.         KillTimer(m_nTimer);
  254. }
  255.